package com.shengqi.xinnongren.work.ui.home.fragments;

import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;

import com.shengqi.xinnongren.R;
import com.shengqi.xinnongren.common.base.BaseLazyLoadFragment;
import com.shengqi.xinnongren.common.config.network.RetrofitHelper;

import butterknife.BindView;

/**
 * Created by LuoYaWei on 2018/9/5.
 */
public class HomePage3Fragment extends BaseLazyLoadFragment {
    @BindView(R.id.wv_web)
    WebView mWebView;

    private String url = RetrofitHelper.BASE_URL + "/api/discovery/index";

    @Override
    protected int setLayoutResource() {
        return R.layout.fragment_home_page3;
    }

    @Override
    protected void lazyLoadData() {

        mWebView.getSettings().setJavaScriptEnabled(true);
        mWebView.setWebViewClient(new MyWebViewClient());
        mWebView.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                super.onProgressChanged(view, newProgress);
            }
        });

        mWebView.loadUrl(url);
    }

    public boolean isWebViewCanGoBack() {
        if (mWebView.canGoBack()) {
            mWebView.goBack();
            return true;
        }
        return false;
    }


    class MyWebViewClient extends WebViewClient {


        @Override
        public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
            return super.shouldOverrideUrlLoading(view, request);
        }
    }
}
